Ext.define('YuXuanResultForm', {
	extend : 'Ext.window.Window',
	id : 'YuXuanResultFormWin',
	layout : 'fit',
	modal : true,
	title : '我的预选题目',
	height : 470,
	width : 800,
	maximizable : true,
	buttonAlign : 'center',

	initComponent : function() {
		
		this.topbar = new Ext.Toolbar({
			items : [{
						iconCls : 'btn-clear',
						text : '移除',
						xtype : 'button',
						scope : this,
						handler : this.removeYuXuans
					}]
		});
		
		this.gridPanel = new KE.GridPanel({
			region : 'center',
			id : 'YuXuanResultGrid',
			tbar : this.topbar,
			url : __ctxPath + "/byxt/listMyYuXuan.do",
			fields : ['oid',{
							name :'subject.oid',
							mapping: 'subject.oid'
						}, {
							name : 'subject.name',
							mapping : 'subject.name'
						}, {
							name : 'subject.teacher.fullname',
							mapping : 'subject.teacher.fullname'
						},'status'],
			
			columns : [{
						header : 'ID',
						dataIndex : 'oid',
						hidden : true
					},{
						header : 'ID2',
						dataIndex : 'subject.oid',
						hidden : true
					}, {
						header : '题目',
						dataIndex : 'subject.name',
						flex: 2
					}, {
						header : '指导教师',
						dataIndex : 'subject.teacher.fullname'
					},{
						header : '预选状态',
						dataIndex : 'status',
						renderer: function(v) { //0：人数已满无法选择 1：可选择 2：待审核 3：审核通过 4：审核不通过
							if(v==0) return '<span class="bg-red">人数已满</span>';
							if(v==1) return '<span class="bg-info">可预选';
							if(v==2) return '<span class="bg-primary">待确认</span>';
							if(v==3) return '<span class="bg-green">预选成功</span>';
							if(v==4) return '<span class="bg-danger">预选失败</span>';
						}
					}]
		});

		this.items = [this.searchPanel, this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);

	},
	rowClick : function(grid, rec) {
		new YuXuanForm({
			sid : rec.data.subject.oid
		}).show();
	},

	removeYuXuans: function() {
		var selRs = this.gridPanel.getSelectionModel().getSelection();
		if(selRs.length == 0) {
			Ext.ux.Toast.msg('操作信息', '请选择要操作的记录！');
			return false;
		}
		var ids = [];
		for(var i=0; i<selRs.length; i++) {
			if(selRs[i].data.status > 2) {
				Ext.ux.Toast.msg('操作信息', '只能移除【待确认】的记录！');
				return false;
			}
			ids.push(selRs[i].data.oid);
		}		
		// 提交
		$postAjax({
			url: __ctxPath + '/byxt/multiDelYuXuan.do',
			params: {
				ids: ids.join(',')
			},
//			grid: this.gridPanel,
			callback: function() {
				var YuXuanGrid=Ext.getCmp('YuXuanGrid');
				YuXuanGrid.getStore().reload();
				var YuXuanResultGrid=Ext.getCmp('YuXuanResultGrid');
				YuXuanResultGrid.getStore().reload();
			}
		});
	}
});

